package com.maxjay.system.web.controller.struts;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.maxjay.system.po.TSysUser;
import com.maxjay.system.service.UserService;

@Scope("prototype")
@Component("changePasswordController")
public class ChangePasswordController extends BaseController {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Resource
	private UserService userService;
	
	private String oldPassword;
	
	private String newPassword;
	
	private String errorMsg;
	private String successMsg;

	@Override
	public String execute() throws Exception {
		TSysUser user = userService.getUser(currentUser.getObjId());
		if(user.getPassword().equals(oldPassword)){
			user.setPassword(newPassword);
			userService.update(user);
			this.refreshCurrentSessionUser(user);
			successMsg = "密码修改成功";
			return INPUT;
		} else {
			this.errorMsg = "原密码错误";
			return INPUT;
		}
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getSuccessMsg() {
		return successMsg;
	}

	public void setSuccessMsg(String successMsg) {
		this.successMsg = successMsg;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}
	
}
